/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SearchView.java
 *
 * Created on 2011-mar-04, 10:27:16
 */

package imat;

import javax.swing.ImageIcon;
import javax.swing.JPanel;
import se.chalmers.ait.dat215.project.IMatDataHandler;
import se.chalmers.ait.dat215.project.Product;

/**
 *
 * @author Boel_
 */
public class SearchView extends javax.swing.JPanel {

    /** Creates new form SearchView */
    public SearchView() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        searchHeaderPanel = new imat.HeaderPanel2();
        resultsPanel = new javax.swing.JPanel();

        setName("Form"); // NOI18N
        setPreferredSize(new java.awt.Dimension(800, 599));

        searchHeaderPanel.setMinimumSize(new java.awt.Dimension(790, 329));
        searchHeaderPanel.setName("searchHeaderPanel"); // NOI18N

        resultsPanel.setName("resultsPanel"); // NOI18N
        resultsPanel.setLayout(new java.awt.GridLayout(0, 2));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(searchHeaderPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 655, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(resultsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 665, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(searchHeaderPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 364, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(resultsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 195, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents
    public void addProduct(Product p){
        itemPanel pa = new itemPanel();
        pa.setProductName(p.getName());
        pa.setProductIcon(new ImageIcon("src/imat/resources/imat/images/"+p.getImageName()));
        pa.setProduct(p);

        if(IMatDataHandler.getInstance().isFavorite(p))
        {
            pa.setStar("src/imat/resources/images/buttons/star.gif");
        }

        pa.setProductPrice(p.getPrice());
        pa.setProductUnitLabel(p.getUnit());
        resultsPanel.add(pa);
        resultsPanel.revalidate();
        resultsPanel.repaint();
    }

    public JPanel getResultsPanel() {
        return resultsPanel;
    }

    public HeaderPanel2 getSearchHeaderPanel() {
        return searchHeaderPanel;
    }

    public void setSearchHeaderPanel(HeaderPanel2 searchHeaderPanel) {
        this.searchHeaderPanel = searchHeaderPanel;
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel resultsPanel;
    private imat.HeaderPanel2 searchHeaderPanel;
    // End of variables declaration//GEN-END:variables

}
